package com.wzy.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Auther: wzy
 * @Date: 2021/11/28/10:54
 * @Description:
 */
@Configuration
public class TestConfiguration {

    /**
     * 适合处理IO密集型任务
     * @author tuan
     * @date 2021/01/20 17:29
     * @return java.util.concurrent.ExecutorService
     */
    @Bean(name = "fullIOThreadPool")
    public ExecutorService getFullIOExecutorService() {
        return new ThreadPoolComponent().getFullIOExecutorService(5, 60L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(80), new ThreadPoolExecutor.CallerRunsPolicy());
    }

    /**
     * 适合CPU计算密集型任务
     * @author tuan
     * @date 2021/01/20 17:29
     * @return java.util.concurrent.ExecutorService
     */
    @Bean(name = "fullCPUEThreadPool")
    public ExecutorService getCPUExecutorService() {
        return new ThreadPoolComponent().getCPUExecutorService(10, 180L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(160), new ThreadPoolExecutor.CallerRunsPolicy());
    }

    /**
     * 单线程池
     * @author tuan
     * @date 2021/01/20 17:29
     * @return java.util.concurrent.ExecutorService
     */
    @Bean(name = "SingleThreadPool")
    public ExecutorService getSingleExecutorService() {
        return new ThreadPoolComponent().getSingleExecutorService();
    }

}
